package indi.kider.server.bill.service;

import indi.kider.common.model.apartment.Houses;
import indi.kider.common.model.bill.MeterAddress;
import indi.kider.common.model.employee.Tenant;
import indi.kider.server.apartment.mapper.HousesMapper;
import indi.kider.server.bill.mapper.ReadingMapper;
import indi.kider.server.employee.mapper.TenantMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import tk.mybatis.mapper.entity.Example;

import java.util.Date;
import java.util.List;

@SuppressWarnings("ALL")
@Service
public class MeterApiServiceImpl implements MeterApiService {

    @Autowired
    private ReadingMapper readingMapper;

    @Autowired
    private HousesMapper housesMapper;

    @Autowired
    private TenantMapper tenantMapper;

    @Override
    public List<MeterAddress> queryMeterAddressByMeterCode(String meterCode, Integer meterType, Date date) {
        if(meterType > 1){
            return readingMapper.queryMeterAddressByPowerMeterCode(meterCode);
        }else {
            return readingMapper.queryMeterAddressByWaterMeterCode(meterCode);
        }
    }

    @Override
    public List<MeterAddress> queryMeterAddressByFloor(List<String> meterCodes, Integer meterType, Date date) {
        if(meterType > 1){
            return readingMapper.queryMeterAddressByPowerMeterCodes(meterCodes);
        }else {
            return readingMapper.queryMeterAddressByWaterMeterCodes(meterCodes);
        }
    }

    @Override
    public List<MeterAddress> queryMeterAddressByCommunityId(String communityCode, Date date) {
        return readingMapper.queryMeterAddressByCommunity(communityCode);
    }

    @Override
    public Houses queryPowerMeterAndWaterMeterByHousesId(Long housesId) {
        return housesMapper.selectByPrimaryKey(housesId);
    }

    @Override
    public Houses queryPowerMeterAndWaterMeterByTenantId(Long tenantId) {
        return housesMapper.queryPowerMeterAndWaterMeterByTenantId(tenantId);
    }

    @Override
    public List<Tenant> queryTenantByIds(List<Long> ids) {
        Example example = new Example(Tenant.class);
        example.createCriteria().andIn("id", ids);
        return tenantMapper.selectByExample(example);
    }

    @Override
    public List<Houses> queryHousesByIds(List<Long> ids) {
        Example example = new Example(Houses.class);
        example.createCriteria().andIn("id", ids);
        return housesMapper.selectByExample(example);
    }
}
